package com.peking.donations.base.service;


import com.peking.donations.base.security.LoggedUser;
import com.peking.donations.base.util.SecurityUtil;

/**
 * 涓氬姟灞倁nchecked寮傚父鍩虹被
 * 閫氬父鎯呭喌涓嬶紝鎴戜滑鍦ㄤ笟鍔￠�昏緫涓姏鍑簎nchecked寮傚父鑰屼笉鏄痗hecked寮傚父锛屼互閬垮厤api鎺ュ彛涓ぇ閲忕殑throws澹版槑銆�
 * 浣嗗鏋滅壒鍒渶瑕乮nvoker澶勭悊鐨勮瘽锛岃繕鏄娇鐢˙izException涓哄疁銆�
 * 
 * @author hawk
 *
 */
public class BizServiceRuntimeException extends RuntimeException {

    /**
	 * 
	 */
    private static final long serialVersionUID = 5305264686660945067L;

    private String code;

    public BizServiceRuntimeException(String msg) {
        super(msg+getInfo());
    }

    public BizServiceRuntimeException(String code, String msg) {
        super(msg+getInfo());
        this.code = code;
    }

    public BizServiceRuntimeException(String msg, Throwable e) {
        super(msg+getInfo(), e);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
    
    private static String getInfo(){
    	LoggedUser user = SecurityUtil.getCurrentUser();
    	if(user==null){
    		return "[ 匿名用户 ]";
    	}else{
    		return " [userId=" + user.getUserId() + ", openId=" + user.getOpenId()
			+ ", username=" + user.getUsername() + "]";
    	}
    		
    }
}
